'use strict';

const BaseModel = require('./BaseModel');

/**
 * 用户权限 表信息
 */

class AdminUserRightsModel extends BaseModel {

  constructor() {
    super('admin_user_rights', 'id');
    this.entity = class entity {
      constructor() {
        this.id = null;
        this.menuId = null;
        this.userId = null;
        this.userRights = null;
        this.controller = null;
        this.creator = null;
        this.createTime = null;
        this.updateTime = null;
      }
    };
  }

  /** ********* 下面添加自定义方法 ************ */

  async deleteByUserId_transaction(conn, userId, logger) {
    const sql = ` delete from ${this.tableName} where user_id = '${userId}'`;
    logger.debug('SQL:', sql);
    return await conn.query(sql);
  }

  async selectUserRightsByUserId(app, userId) {
    const sql = ` select menu_id,controller,user_rights from ${this.tableName} where user_id = '${userId}'`;
    app.logger.debug('SQL:', sql);
    const results = await app.mysql.query(sql);
    if (results && results.length > 0) {
      const adminUserRightsList = [];
      for (const dbentity of results) {
        let userRights = new this.entity();
        userRights = this.transformation_Entity(dbentity);
        adminUserRightsList.push(userRights);
      }
      return adminUserRightsList;
    }
    return [];
  }

  

}

module.exports = AdminUserRightsModel;
